package org.kele.k8s.sc2020.user.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.ListUtil;
import lombok.extern.slf4j.Slf4j;
import org.kele.k8s.sc2020.ex.BizRuntimeExecption;
import org.kele.k8s.sc2020.vo.KeleResponse;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RequestMapping("/user")
@RestController
public class UserLoginController {

    @PostMapping("/kele/login")
    public KeleResponse<Object> doLogin(@RequestBody Map<String, String> map) {
        if (map.get("username").equals("kele")) {
            StpUtil.login(1);
            return KeleResponse.okBean(StpUtil.getTokenInfo());
        }
        throw new BizRuntimeExecption("001", "username or password incorrect!!");
    }

    @GetMapping("/kele/roles/{uid}")
    public KeleResponse<List<String>> getRoles(@PathVariable String uid) {
        return KeleResponse.okBean(ListUtil.of("admin", "viewer"));
    }

    @GetMapping("/kele/permissions/{uid}")
    public KeleResponse<List<String>> getPermissions(@PathVariable String uid) {
        return KeleResponse.okBean(ListUtil.of("add", "edit", "del", "get", "list", "watch"));
    }

}
